package com.jcx.ldzj.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.jcx.ldzj.entity.GenTableCretearInfo;
import com.jcx.ldzj.service.IGenTableCretear;
import com.jcx.ldzj.utile.ExcelUtile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Slf4j
@AllArgsConstructor
@RequestMapping("/genTable")
@Api(value = "数据库表汇总查询", tags = "数据库表汇总查询")
public class GenTableCretearController extends ApiController {
    @Autowired
    private IGenTableCretear iGenTableCretear;

    /**
     * 将数据库表字段下载下来导出excel
     * @param tableSchema 数据库名称
     * @param response
     * @param request
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表", notes = "传入表名称")
    public String genTableExcel(String tableSchema, HttpServletResponse response, HttpServletRequest request){
        List<GenTableCretearInfo> genTableCretearInfos = iGenTableCretear.selectAll(tableSchema);
        ExcelUtile.download("数据库表汇总.xls",genTableCretearInfos,response,request);
        return null;
    }
}
